package outputstream;

import org.junit.Test;

import java.io.*;

public class BufferdOutputStream_Copy {
    public static void main(String[] args) {

    }

    @Test
    public void copy() {
        BufferedInputStream bufferedInputStream = null;
        BufferedOutputStream bufferedOutputStream = null;
        int len=0;
        byte[] bytes = new byte[1024];

        try {
            bufferedInputStream = new BufferedInputStream(new FileInputStream("D:\\周杰伦无损FLAC歌曲\\其他音乐\\光年之外.mp3"));
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("D:\\xuexi\\光年之外.mp3"));
            while ((len=bufferedInputStream.read(bytes))!=-1){
                bufferedOutputStream.write(bytes,0,len);
            }
            System.out.println("歌曲复制成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedInputStream.close();
                bufferedOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
